﻿@model IEnumerable<CurriculaAPI.ViewModelDTO.ProfessorListDTO>

@{
    ViewBag.Title = "Default";
}

<h2>大学教授列表页面</h2>
<a href="~/Specialist/Default">专家列表</a>

@using (Html.BeginForm("Default", "Home", FormMethod.Post))
{
    <label>姓名：</label>
    <input name="Name" type="text" />
    <label>专业类别：</label>
    @Html.DropDownList("CategoryName", ViewBag.CategoryNameList as IEnumerable<SelectListItem>, "--请选择专业类别--")
    <label>课程名字：</label>
    @Html.DropDownList("CourseName", ViewBag.CourseNameList as IEnumerable<SelectListItem>, "--请选择课程名字--")

    <input class="btn btn-default" type="submit" value="查询" />
    <a class="btn btn-default" href="@Url.Action("Add","Home")">添加</a>
}
<table class="table">
    <tr>
        <th>
            姓名
        </th>
        <th>
            头像照片
        </th>
        <th>
            性别
        </th>
        <th>
            专业类别
        </th>
        <th>
            课程名字
        </th>
        <th>
            职称名称
        </th>
        <th>
            上课时间
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Avatar)
            </td>
            <td>
                @(item.Sex == 1 ? "男" : "女")
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CategoryName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CourseName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TitleName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CreateDateTime)
            </td>
            <td>
                <a class="btn btn-warning" href="@Url.Action("Edit", "Home", new { id = item.ID })">编辑</a>
                <a class="btn btn-danger" href="javascript:;" onclick="Delete(@item.ID)">删除</a>
            </td>
        </tr>
    }

</table>
<script>
    function Delete(id) {
        if (confirm("你确定要删除吗?")) {
            $.post(
                "@Url.Action("Delete", "Home")", { id: id }, function (data) {
                    if (data.State == 1) {
                        alert(data.Message);
                        location.reload();
                    } else {
                        alert(data.Message);
                    }
                }
            );
        }
    }
</script>